#include "room.hpp"

Room::~Room()
{
	TableMap_Iter iter = _table_map.begin();
	for (; iter != _table_map.end(); ++ iter)
	{
		delete iter->second;
	}
	_table_map.clear();
}

Table * Room::find_table(TABLEID id)
{
	TableMap_Iter iter = _table_map.find(id);
	if (_table_map.end() == iter)
	{
		return NULL;
	}

	return iter->second;
}

Room::Id Room::select_table(const RoleB & role_b)
{
	int mark    = 0;
	SEATID sid  = 0;

	Id  id;

	TableMap_Iter iter = _table_map.begin();
	for (; iter != _table_map.end(); ++ iter)
	{
		Table * table = iter->second;
		int mk        = table->match(role_b, sid);
		
		if (mark < mk)
		{
			mark  = mk;
			id._tid  = table->_id;
			id._sid  = sid;
		}
	}

	return id;
}

